<template>
    <div class='choice-single'>
        <Singlelist :resource = 'goods'></Singlelist>
    </div>
</template>

<script>
    import Singlelist from 'components/commons/single/single-list.vue'
    import { Indicator , Toast } from 'mint-ui';
    import BScroll from 'better-scroll'
    import axios from 'axios'
    export default {
        data(){
            return{
                pages:1,
                goods: null
            }
        },
        components:{
            Singlelist
        },
        created(){
            axios.get('/api/getGoods',{
                params:{
                    page: this.pages,
                    zy_ids: 'p8_c4_l4',
                    app_name: 'zhe',
                    catname: 'tab_hpdp',
                    flag: 'tab_hpdp'
                }
            })
            .then(res=>{
                this.goods = res.data.data.goods
            })
            .catch(err=>console.log(err))
        },
        watch:{
            goods(){
                let that = this
                that.scroll = new BScroll('.home-wrapper',{
                     pullUpLoad: {
                        threshold: 20
                    },
                    click:true
                })
                that.scroll.on('pullingUp',()=>{

                    that.pages++
                    axios.get('/api/getGoods',{
                        params:{
                            page: that.pages,
                            zy_ids: 'p8_c4_l4',
                            app_name: 'zhe',
                            catname: 'tab_hpzc',
                            flag: 'tab_hpzc'
                        }
                    })
                    .then(res=>{
                        let data = res.data.data.goods
                        that.goods.push(...data)
                        that.$nextTick(() => {
                            that.scroll.refresh()
                        })
                    })
                    .catch(err=>console.log(err))
                })
                 that.scroll.finishPullUp()
            }
        }
    }

</script>
</script>